package homeworke.question17;

/**
 * Author：毕龙
 * Date: 2024/4/18 19:26
 */
public class Team {
    private Role[] roles = new Role[6];
    private int countNum;  //统计团队组员的数量
    //添加队员
    public void addMember(Role role){
        if(countNum < roles.length){
            roles[countNum] = role;//将该角色放在数组中
            countNum ++;//加一个角色 加1
        }
    }
    public int attackSum(){
        int attackSum = 0;
        //遍历数组
        for (int i = 0; i < countNum; i++) {
            //子类重写了父类的攻击方法执行时调用子类的攻击方法
            attackSum += roles[i].attack();
        }
        return attackSum;
    }
}
